package com.sojpt.boot.controller.business.validator;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;
import com.sojpt.model.LkyEvaluation;

/**
 * Description: 本类用于评定成绩的添加
 * Created by SMW on 2020/3/27 22:17
 */
public class LkyEvaluationValidator extends Validator {

    @Override
    protected void validate(Controller controller) {
        LkyEvaluation lkyEvaluation = controller.getModel(LkyEvaluation.class,"lkyevaluation");
        if (lkyEvaluation.get("training_project")!=null){
            validateString("lkyEvaluation.training_project",0,200,"msg","最多200字符");
            validateRequired("lkyEvaluation.training_project","msg","请输入实训名称");
        }
        if(lkyEvaluation.get("start_time") != null)
            validateDate("lkyEvaluation.start_time", "msg", "开始时间: "+lkyEvaluation.get("lkyEvaluation.start_time")+" 格式错误");
        validateRequired("lkyEvaluation.start_time", "msg", "请输入开始时间");

        if(lkyEvaluation.get("end_time") != null)
            validateDate("lkyEvaluation.end_time", "msg", "结束时间: "+lkyEvaluation.get("lkyEvaluation.end_time")+" 格式错误");
        validateRequired("lkyEvaluation.end_time", "msg", "请输入结束时间");

        if (lkyEvaluation.get("training_site")!=null){
            validateString("lkyEvaluation.training_site",0,200,"msg","最多200字符");
            validateRequired("lkyEvaluation.training_site","msg","请输入实训地点");
        }
        if (lkyEvaluation.get("guidance_teacher")!=null){
            validateString("lkyEvaluation.guidance_teacher",0,200,"msg","最多200字符");
            validateRequired("lkyEvaluation.guidance_teacher","msg","请输入指导老师");
        }
        if (lkyEvaluation.get("score")!=null){
            validateString("lkyEvaluation.score",0,200,"msg","最多200字符");
            validateRequired("lkyEvaluation.score","msg","请输入分数");
        }
    }

    @Override
    protected void handleError(Controller controller) {
        controller.renderJson();
    }
}
